/**********************************************************
 * AJAXAction.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 10:44:25 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.action;

import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionSupport;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.LocationCategoriesServiceDelegator;
import com.printeverywhere.delegator.SearchServiceDelegator;
import com.printeverywhere.dto.GeneralCategoriesWOS;
import com.printeverywhere.dto.Itemtype;
import com.printeverywhere.dto.Languages;
import com.printeverywhere.dto.LocationCategories;
import com.printeverywhere.dto.LocationCategoriesWOS;

// TODO: Auto-generated Javadoc
/**
 * The Class AJAXAction.
 */
public class AJAXAction extends ActionSupport implements ServletRequestAware,
		ServletResponseAware {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(AJAXAction.class);

	/** The request. */
	private HttpServletRequest request;

	/** The response. */
	private HttpServletResponse response;

	/** The input stream. */
	private InputStream inputStream;

	/**
	 * Gets the input stream.
	 *
	 * @return the input stream
	 */
	public InputStream getInputStream() {
		return inputStream;
	}

	/**
	 * Gets the country.
	 *
	 * @return the country
	 *
	 * @throws Exception the exception
	 */
	public String getCountry() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getCountry() - start"); //$NON-NLS-1$
		}

		int regionId = Integer.parseInt(request.getParameter("showCountry"));

		StringBuffer result = new StringBuffer("");
		result.append("<list>\n");
		List<LocationCategories> countryList = LocationCategoriesServiceDelegator
				.getCountryListByRegionId(regionId);
		int totalCountry = countryList.size();
		result.append(" <option value=\"0\">" + "Select Country "
				+ "</option>\n");
		if (countryList != null) {
			for (int index = 0; index < totalCountry; index++) {
				result.append(" <option value=\""
						+ ((LocationCategories) countryList.get(index))
								.getCategoryId()
						+ "\">"
						+ ((LocationCategories) countryList.get(index))
								.getCategoryName() + "</option>\n");
			}
		}
		result.append("</list>\n");
		inputStream = new StringBufferInputStream(result.toString());

		if (logger.isDebugEnabled()) {
			logger.debug("getCountry() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Gets the states.
	 *
	 * @return the states
	 *
	 * @throws Exception the exception
	 */
	public String getStates() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getStates() - start"); //$NON-NLS-1$
		}

		int countryId = Integer.parseInt(request.getParameter("showStates"));
		StringBuffer result = new StringBuffer("");
		result.append("<list>\n");
		List<LocationCategories> statesList = LocationCategoriesServiceDelegator
				.getStateListByCountryId(countryId);
		int totalStates = statesList.size();

		if (statesList != null) {
			for (int index = 0; index < totalStates; index++) {
				result.append(" <option value=\""
						+ ((LocationCategories) statesList.get(index))
								.getCategoryId()
						+ "\">"
						+ ((LocationCategories) statesList.get(index))
								.getCategoryName() + "</option>\n");
			}
		}
		result.append("</list>\n");

		inputStream = new StringBufferInputStream(result.toString());

		if (logger.isDebugEnabled()) {
			logger.debug("getStates() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	public String getCountryListingOptions() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getCountriesForList() - start"); //$NON-NLS-1$
		}

		int regionId = Integer.parseInt(request.getParameter("showCountry"));
		StringBuffer result = new StringBuffer("");
		result.append("<select name=\"listingOptions.defaultCountry\">\n");
		List<LocationCategories> statesList = LocationCategoriesServiceDelegator
				.getCountryListByRegionId(regionId);
		int totalStates = statesList.size();

		if (statesList != null) {
			for (int index = 0; index < totalStates; index++) {
				result.append(" <option value=\""
						+ ((LocationCategories) statesList.get(index))
								.getCategoryId()
						+ "\">"
						+ ((LocationCategories) statesList.get(index))
								.getCategoryName() + "</option>\n");
			}
		}
		result.append("</select>\n");
		inputStream = new StringBufferInputStream(result.toString());

		if (logger.isDebugEnabled()) {
			logger.debug("getCountriesForList() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	public String getStatesOwnerDetails() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getStatesForList() - start"); //$NON-NLS-1$
		}

		int countryId = Integer.parseInt(request.getParameter("showStates"));
		StringBuffer result = new StringBuffer("");
		result.append("<select name=\"adminDetails.state\">\n");
		List<LocationCategories> statesList = LocationCategoriesServiceDelegator
				.getStateListByCountryId(countryId);
		int totalStates = statesList.size();

		if (statesList != null) {
			for (int index = 0; index < totalStates; index++) {
				result.append(" <option value=\""
						+ ((LocationCategories) statesList.get(index))
								.getCategoryId()
						+ "\">"
						+ ((LocationCategories) statesList.get(index))
								.getCategoryName() + "</option>\n");
			}
		}
		result.append("</select>\n");
		inputStream = new StringBufferInputStream(result.toString());

		if (logger.isDebugEnabled()) {
			logger.debug("getStatesForList() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	public String updateSearchBox() throws Exception {
 		if (logger.isDebugEnabled()) {
 			logger.debug("getCountry() - start"); //$NON-NLS-1$
 		}

 			int typeId = Integer.parseInt(request.getParameter("ItemType"));
 			int catId = Integer.parseInt(request.getParameter("categories"));
 			int locId = Integer.parseInt(request.getParameter("locations"));
 			String langId = request.getParameter("languages");

 	       StringBuffer result = new StringBuffer("");

 	      removeElement(result, "ItemType");
	       List<Itemtype> itemList = (List<Itemtype>) CommonFunctionDelegator.getAllfromtable(Itemtype.class.getName());
	       int index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
	       result.append("anOption.text = \"All items for sale (").append(SearchServiceDelegator.getItemCountForParent(0, catId, locId, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('ItemType').options.add(anOption);");

	       for (Itemtype itemtype : itemList) {
	    	   result.append("var anOption = document.createElement(\"OPTION\");");
	    	   result.append("anOption.text = \"").append(itemtype.getType()).append(" (").append(SearchServiceDelegator.getItemCountForParent(itemtype.getId(), catId, locId, langId)).append(")").append("\";");
		       result.append("anOption.value = \"").append(itemtype.getId()).append("\";");
		       result.append("document.getElementById('ItemType').options.add(anOption);");
		       if (typeId == itemtype.getId()) {
		    	   result.append("document.getElementById('ItemType').selectedIndex = ").append(index).append(";");
		       }
		       index++;
	       }

 	       removeElement(result, "categories");
	       List<GeneralCategoriesWOS> catList = getAllCategoriesById(Integer.parseInt(request.getParameter("categories")));
	       index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
    	   result.append("anOption.text = \"Select Category (").append(SearchServiceDelegator.getItemCountForParent(typeId, 0, locId, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('categories').options.add(anOption);");

	       String arrow = "-";
	       if (catId != 0) {
	    	   List<GeneralCategoriesWOS> parents = new ArrayList<GeneralCategoriesWOS>();
	    	   boolean flag = true;
	    	   int tmpCatId = catId;
	    	   while(flag) {
	    		   GeneralCategoriesWOS category = (GeneralCategoriesWOS) CommonFunctionDelegator.getObjectById("categoryId", tmpCatId, GeneralCategoriesWOS.class);
	    		   if(category.getCategoryId() == category.getGeneralCategories().getCategoryId()) {
	    			   parents.add(category);
	    			   flag = false;
	    		   } else {
	    			   tmpCatId = category.getGeneralCategories().getCategoryId();
	    			   parents.add(category);
	    		   }
	    	   }

	    	   Collections.reverse(parents);

	    	   for (GeneralCategoriesWOS generalCategoriesWOS : parents) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	        	   result.append("anOption.text = \"").append(arrow).append("> ").append(generalCategoriesWOS.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, generalCategoriesWOS.getCategoryId(), locId, langId)).append(")").append("\";");
	    	       result.append("anOption.value = \"").append(generalCategoriesWOS.getCategoryId()).append("\";");
	    	       result.append("document.getElementById('categories').options.add(anOption);");

	    	       if(catId == generalCategoriesWOS.getCategoryId())
	    	    	   result.append("document.getElementById('categories').selectedIndex = ").append(index).append(";");

	    	       arrow = "-" + arrow;
	    	       index++;
	    	   }
	       }

	       if(arrow.equals("-"))
	    	   arrow = "";
	       for (GeneralCategoriesWOS category : catList) {
	    	   if (catId != category.getCategoryId()) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	    		   result.append("anOption.text = \"").append(arrow).append(" ").append(category.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, category.getCategoryId(), locId, langId)).append(")").append("\";");
	    		   result.append("anOption.value = \"").append(category.getCategoryId()).append("\";");
	    		   result.append("document.getElementById('categories').options.add(anOption);");
	    	   }
	       }

 	       removeElement(result, "locations");
 	       List<LocationCategoriesWOS> locList = getAllLocationById(Integer.parseInt(request.getParameter("locations")));
	       index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
    	   result.append("anOption.text = \"Select Location (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, 0, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('locations').options.add(anOption);");

	       arrow = "-";
	       if (locId != 0) {
	    	   List<LocationCategoriesWOS> parents = new ArrayList<LocationCategoriesWOS>();
	    	   boolean flag = true;
	    	   int tmpLocId = locId;
	    	   while(flag) {
	    		   LocationCategoriesWOS category = (LocationCategoriesWOS) CommonFunctionDelegator.getObjectById("categoryId", tmpLocId, LocationCategoriesWOS.class);
	    		   if(category.getCategoryId() == category.getLocationCategories().getCategoryId()) {
	    			   parents.add(category);
	    			   flag = false;
	    		   } else {
	    			   tmpLocId = category.getLocationCategories().getCategoryId();
	    			   parents.add(category);
	    		   }
	    	   }
	    	   Collections.reverse(parents);

	    	   for (LocationCategoriesWOS locationCategoriesWOS : parents) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	        	   result.append("anOption.text = \"").append(arrow).append("> ").append(locationCategoriesWOS.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locationCategoriesWOS.getCategoryId(), langId)).append(")").append("\";");
	    	       result.append("anOption.value = \"").append(locationCategoriesWOS.getCategoryId()).append("\";");
	    	       result.append("document.getElementById('locations').options.add(anOption);");

	    	       if(locId == locationCategoriesWOS.getCategoryId())
	    	    	   result.append("document.getElementById('locations').selectedIndex = ").append(index).append(";");

	    	       arrow = "-" + arrow;
	    	       index++;
	    	   }
	       }

	       if(arrow.equals("-"))
	    	   arrow = "";

	       for (LocationCategoriesWOS location : locList) {
	    	   if (locId != location.getCategoryId()) {
		    	   result.append("var anOption = document.createElement(\"OPTION\");");
		    	   result.append("anOption.text = \"").append(arrow).append(" ").append(location.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, location.getCategoryId(), langId)).append(")").append("\";");
			       result.append("anOption.value = \"").append(location.getCategoryId()).append("\";");
			       result.append("document.getElementById('locations').options.add(anOption);");
			   }
		       index++;
	       }

 	       removeElement(result, "languages");
 	       List<Languages> langList = getAllLanguages();
 	       index = 1;

 	       result.append("var anOption = document.createElement(\"OPTION\");");
 	       result.append("anOption.text = \"Select Language (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locId, "0")).append(")\";");
 	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('languages').options.add(anOption);");

	       for (Languages language : langList) {
	    	   result.append("var anOption = document.createElement(\"OPTION\");");
	    	   result.append("anOption.text = \"").append(language.getLanguageName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locId, language.getLanguageCode())).append(")").append("\";");
		       result.append("anOption.value = \"").append(language.getLanguageCode()).append("\";");
		       result.append("document.getElementById('languages').options.add(anOption);");
		       if (request.getParameter("languages").equals(language.getLanguageCode())) {
		    	   result.append("document.getElementById('languages').selectedIndex = ").append(index).append(";");
		       }
		       index++;
	       }


 	       inputStream = new StringBufferInputStream(result.toString());

 		if (logger.isDebugEnabled()) {
 			logger.debug("getCountry() - end"); //$NON-NLS-1$
 		}
 	       return SUCCESS;
 	  }

	public String updateSmartSearchBox() throws Exception {
 		if (logger.isDebugEnabled()) {
 			logger.debug("getCountry() - start"); //$NON-NLS-1$
 		}

 			int typeId = Integer.parseInt(request.getParameter("ItemType"));
 			int catId = Integer.parseInt(request.getParameter("categories"));
 			int locId = Integer.parseInt(request.getParameter("locations"));
 			String langId = request.getParameter("languages");

 	       StringBuffer result = new StringBuffer("");

 	      removeElement(result, "SmartItemType");
	       List<Itemtype> itemList = (List<Itemtype>) CommonFunctionDelegator.getAllfromtable(Itemtype.class.getName());
	       int index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
	       result.append("anOption.text = \"All items for sale (").append(SearchServiceDelegator.getItemCountForParent(0, catId, locId, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('SmartItemType').options.add(anOption);");

	       for (Itemtype itemtype : itemList) {
	    	   result.append("var anOption = document.createElement(\"OPTION\");");
	    	   result.append("anOption.text = \"").append(itemtype.getType()).append(" (").append(SearchServiceDelegator.getItemCountForParent(itemtype.getId(), catId, locId, langId)).append(")").append("\";");
		       result.append("anOption.value = \"").append(itemtype.getId()).append("\";");
		       result.append("document.getElementById('SmartItemType').options.add(anOption);");
		       if (typeId == itemtype.getId()) {
		    	   result.append("document.getElementById('SmartItemType').selectedIndex = ").append(index).append(";");
		       }
		       index++;
	       }

 	       removeElement(result, "smartcategories");
	       List<GeneralCategoriesWOS> catList = getAllCategoriesById(Integer.parseInt(request.getParameter("categories")));
	       index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
    	   result.append("anOption.text = \"Select Category (").append(SearchServiceDelegator.getItemCountForParent(typeId, 0, locId, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('smartcategories').options.add(anOption);");

	       String arrow = "-";
	       if (catId != 0) {
	    	   List<GeneralCategoriesWOS> parents = new ArrayList<GeneralCategoriesWOS>();
	    	   boolean flag = true;
	    	   int tmpCatId = catId;
	    	   while(flag) {
	    		   GeneralCategoriesWOS category = (GeneralCategoriesWOS) CommonFunctionDelegator.getObjectById("categoryId", tmpCatId, GeneralCategoriesWOS.class);
	    		   if(category.getCategoryId() == category.getGeneralCategories().getCategoryId()) {
	    			   parents.add(category);
	    			   flag = false;
	    		   } else {
	    			   tmpCatId = category.getGeneralCategories().getCategoryId();
	    			   parents.add(category);
	    		   }
	    	   }

	    	   Collections.reverse(parents);

	    	   for (GeneralCategoriesWOS generalCategoriesWOS : parents) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	        	   result.append("anOption.text = \"").append(arrow).append("> ").append(generalCategoriesWOS.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, generalCategoriesWOS.getCategoryId(), locId, langId)).append(")").append("\";");
	    	       result.append("anOption.value = \"").append(generalCategoriesWOS.getCategoryId()).append("\";");
	    	       result.append("document.getElementById('smartcategories').options.add(anOption);");

	    	       if(catId == generalCategoriesWOS.getCategoryId())
	    	    	   result.append("document.getElementById('smartcategories').selectedIndex = ").append(index).append(";");

	    	       arrow = "-" + arrow;
	    	       index++;
	    	   }
	       }

	       if(arrow.equals("-"))
	    	   arrow = "";
	       for (GeneralCategoriesWOS category : catList) {
	    	   if (catId != category.getCategoryId()) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	    		   result.append("anOption.text = \"").append(arrow).append(" ").append(category.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, category.getCategoryId(), locId, langId)).append(")").append("\";");
	    		   result.append("anOption.value = \"").append(category.getCategoryId()).append("\";");
	    		   result.append("document.getElementById('smartcategories').options.add(anOption);");
	    	   }
	       }

 	       removeElement(result, "smartlocations");
 	       List<LocationCategoriesWOS> locList = getAllLocationById(Integer.parseInt(request.getParameter("locations")));
	       index = 1;

	       result.append("var anOption = document.createElement(\"OPTION\");");
    	   result.append("anOption.text = \"Select Location (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, 0, langId)).append(")\";");
	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('smartlocations').options.add(anOption);");

	       arrow = "-";
	       if (locId != 0) {
	    	   List<LocationCategoriesWOS> parents = new ArrayList<LocationCategoriesWOS>();
	    	   boolean flag = true;
	    	   int tmpLocId = locId;
	    	   while(flag) {
	    		   LocationCategoriesWOS category = (LocationCategoriesWOS) CommonFunctionDelegator.getObjectById("categoryId", tmpLocId, LocationCategoriesWOS.class);
	    		   if(category.getCategoryId() == category.getLocationCategories().getCategoryId()) {
	    			   parents.add(category);
	    			   flag = false;
	    		   } else {
	    			   tmpLocId = category.getLocationCategories().getCategoryId();
	    			   parents.add(category);
	    		   }
	    	   }
	    	   Collections.reverse(parents);

	    	   for (LocationCategoriesWOS locationCategoriesWOS : parents) {
	    		   result.append("var anOption = document.createElement(\"OPTION\");");
	        	   result.append("anOption.text = \"").append(arrow).append("> ").append(locationCategoriesWOS.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locationCategoriesWOS.getCategoryId(), langId)).append(")").append("\";");
	    	       result.append("anOption.value = \"").append(locationCategoriesWOS.getCategoryId()).append("\";");
	    	       result.append("document.getElementById('smartlocations').options.add(anOption);");

	    	       if(locId == locationCategoriesWOS.getCategoryId())
	    	    	   result.append("document.getElementById('smartlocations').selectedIndex = ").append(index).append(";");

	    	       arrow = "-" + arrow;
	    	       index++;
	    	   }
	       }

	       if(arrow.equals("-"))
	    	   arrow = "";

	       for (LocationCategoriesWOS location : locList) {
	    	   if (locId != location.getCategoryId()) {
		    	   result.append("var anOption = document.createElement(\"OPTION\");");
		    	   result.append("anOption.text = \"").append(arrow).append(" ").append(location.getCategoryName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, location.getCategoryId(), langId)).append(")").append("\";");
			       result.append("anOption.value = \"").append(location.getCategoryId()).append("\";");
			       result.append("document.getElementById('smartlocations').options.add(anOption);");
			   }
		       index++;
	       }

 	       removeElement(result, "smartlanguages");
 	       List<Languages> langList = getAllLanguages();
 	       index = 1;

 	       result.append("var anOption = document.createElement(\"OPTION\");");
 	       result.append("anOption.text = \"Select Language (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locId, "0")).append(")\";");
 	       result.append("anOption.value = \"0\";");
	       result.append("document.getElementById('smartlanguages').options.add(anOption);");

	       for (Languages language : langList) {
	    	   result.append("var anOption = document.createElement(\"OPTION\");");
	    	   result.append("anOption.text = \"").append(language.getLanguageName()).append(" (").append(SearchServiceDelegator.getItemCountForParent(typeId, catId, locId, language.getLanguageCode())).append(")").append("\";");
		       result.append("anOption.value = \"").append(language.getLanguageCode()).append("\";");
		       result.append("document.getElementById('smartlanguages').options.add(anOption);");
		       if (request.getParameter("languages").equals(language.getLanguageCode())) {
		    	   result.append("document.getElementById('smartlanguages').selectedIndex = ").append(index).append(";");
		       }
		       index++;
	       }


 	       inputStream = new StringBufferInputStream(result.toString());

 		if (logger.isDebugEnabled()) {
 			logger.debug("getCountry() - end"); //$NON-NLS-1$
 		}
 	       return SUCCESS;
 	  }

	private void removeElement(StringBuffer result, String element) {
		result.append("var elSel = document.getElementById('" + element + "');");
	    result.append("var i;");
	    result.append("for (i = elSel.length - 1; i>=0; i--) {");
	    result.append("elSel.remove(i);");
	    result.append("}");
	}

	private List<GeneralCategoriesWOS> getAllCategoriesById(int id) {
		List<Criterion> criterionList = new ArrayList<Criterion>();
		if (id != 0) {
			criterionList.add(Restrictions.eq("generalCategories.categoryId", id));
		}
		criterionList.add(Restrictions.eq("active", true));
		return (List<GeneralCategoriesWOS>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, GeneralCategoriesWOS.class);
	}

	private List<LocationCategoriesWOS> getAllLocationById(int id) {
		List<Criterion> criterionList = new ArrayList<Criterion>();
		if (id != 0) {
			criterionList.add(Restrictions.eq("locationCategories.categoryId", id));
		} else {
			criterionList.add(Restrictions.eq("level", 1));
		}
		return (List<LocationCategoriesWOS>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, LocationCategoriesWOS.class);
	}

	private List<Languages> getAllLanguages() {
		List<Criterion> criterionList = new ArrayList<Criterion>();
		criterionList.add(Restrictions.eq("active", true));
		return (List<Languages>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, Languages.class);
	}

	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)
	 */
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
}